CSharpTest.Net
Merge(IComparer<TKey>,DuplicateHandling,IEnumerable<KeyValuePair<TKey,TValue>>[]) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > OrderedKeyValuePairs<TKey,TValue> Class > Merge Method : Merge(IComparer<TKey>,DuplicateHandling,IEnumerable<KeyValuePair<TKey,TValue>>[]) Method

comparer
duplicateHandling
enums

Glossary Item Box

Merges n-number of ordered enumerations based on the comparer provided.

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function Merge( _
   ByVal comparer As IComparer(Of TKey), _
   ByVal duplicateHandling As DuplicateHandling, _
   ByVal ParamArray enums() As IEnumerable(Of KeyValuePair(Of TKey,TValue)) _
) As IEnumerable(Of KeyValuePair(Of TKey,TValue))

Parameters

comparer
duplicateHandling
enums

Example

Library/Library.Test/TestOrderedEnumeration.cs

C#Copy Code
var x = new[] { new KeyValuePair<int, int>(1, 1) };
var y = new[] { new KeyValuePair<int, int>(1, 2), new KeyValuePair<int, int>(2, 2) };

IEnumerator<KeyValuePair<int, int>> e =
    OrderedKeyValuePairs<int, int>
    .Merge(Comparer<int>.Default, DuplicateHandling.FirstValueWins, x, y)
    .GetEnumerator();

Assert.IsTrue(e.MoveNext());
Assert.AreEqual(1, e.Current.Key);
Assert.AreEqual(1, e.Current.Value);
Assert.IsTrue(e.MoveNext());
Assert.AreEqual(2, e.Current.Key);
Assert.AreEqual(2, e.Current.Value);
Assert.IsFalse(e.MoveNext());
            
e = OrderedKeyValuePairs<int, int>
    .Merge(Comparer<int>.Default, DuplicateHandling.LastValueWins, x, y)
    .GetEnumerator();

Assert.IsTrue(e.MoveNext());
Assert.AreEqual(1, e.Current.Key);
Assert.AreEqual(2, e.Current.Value);
Assert.IsTrue(e.MoveNext());
Assert.AreEqual(2, e.Current.Key);
Assert.AreEqual(2, e.Current.Value);
Assert.IsFalse(e.MoveNext());
VB.NETCopy Code
Dim x As var = New () {New KeyValuePair(Of Integer, Integer)(1, 1)}
Dim y As var = New () {New KeyValuePair(Of Integer, Integer)(1, 2), New KeyValuePair(Of Integer, Integer)(2, 2)}

Dim e As IEnumerator(Of KeyValuePair(Of Integer, Integer)) = OrderedKeyValuePairs(Of Integer, Integer).Merge(Comparer(Of Integer).[Default], DuplicateHandling.FirstValueWins, x, y).GetEnumerator()

Assert.IsTrue(e.MoveNext())
Assert.AreEqual(1, e.Current.Key)
Assert.AreEqual(1, e.Current.Value)
Assert.IsTrue(e.MoveNext())
Assert.AreEqual(2, e.Current.Key)
Assert.AreEqual(2, e.Current.Value)
Assert.IsFalse(e.MoveNext())

e = OrderedKeyValuePairs(Of Integer, Integer).Merge(Comparer(Of Integer).[Default], DuplicateHandling.LastValueWins, x, y).GetEnumerator()

Assert.IsTrue(e.MoveNext())
Assert.AreEqual(1, e.Current.Key)
Assert.AreEqual(2, e.Current.Value)
Assert.IsTrue(e.MoveNext())
Assert.AreEqual(2, e.Current.Key)
Assert.AreEqual(2, e.Current.Value)
Assert.IsFalse(e.MoveNext())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys